﻿var MoveAsync = eval(Jscex.compile("async", function(e, startPos, endPos, duration) {
    for (var t = 0; t < duration; t += 50) {
        e.style.left = (startPos.x + (endPos.x - startPos.x) * t / duration) + "px";
        e.style.top = (startPos.y + (endPos.y - startPos.y) * t / duration) + "px";
        $await(Jscex.Async.sleep(50));
    }

    e.style.left = endPos.x;
    e.style.top = endPos.y;
}));

var LengthAnimation = eval(Jscex.compile("async", function(e, startLength, endLength, widthOrHeight, fixedPosition, duration) {
    if (widthOrHeight == "width") {
        //宽度变化
        if (fixedPosition == "left") {
            //左边固定，即从右向左渐变的效果
            var left = e.style.left;
            var top = e.style.top;
            for (var t = 0; t < duration; t += 50) {
                e.width = (startLength + (endLength - startLength) * t / duration) + "px";
                e.style.left = left;
                e.style.top = top;
                $await(Jscex.Async.sleep(50));
            }
            e.width = endLength;
        }
        else if (fixedPosition == "right") {
            //右边固定，即从左向右渐变的效果
            var right = e.style.right;
            var top = e.style.top;
            for (var t = 0; t < duration; t += 50) {
                e.width = (startLength + (endLength - startLength) * t / duration) + "px";
                e.style.right = right;
                e.style.top = top;
                $await(Jscex.Async.sleep(50));
            }
            e.width = endLength;
        }
        else {

        }
    }
    else {
        //高度变化
        if (fixedPosition == "top") {
            //顶端固定 即从下向上渐变的效果

        }
        else if (fixedPosition == "bottom") {
            //低端固定 即从上向下渐变的效果

        }
        else {

        }

    }

}));